package tech.chauncy.springbootwebsample.service;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.BeanAccess;
import tech.chauncy.springbootwebsample.entity.ConditionEntity;
import tech.chauncy.springbootwebsample.entity.OutputsEntity;
import tech.chauncy.springbootwebsample.entity.ProcessTestEntity;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Created by sunjia on 2018/3/6.
 */
public class SnakeYaml {

    public static void main(String[] args){

       try {
            Yaml yaml = new Yaml();
            URL url = SnakeYaml.class.getClassLoader().getResource("1.yaml");
            if (url != null) {
                ProcessTestEntity processSample =yaml.loadAs(new FileInputStream(url.getFile()), ProcessTestEntity.class);
                List<OutputsEntity> outputs = processSample.getOutputs();
                for (OutputsEntity output : outputs){
                    String APIname = output.getName();
                    List<ConditionEntity> conditions = output.getConditions();
                    for(ConditionEntity conditionEntity : conditions){
                        String condition = conditionEntity.getCondition();
                        String result = conditionEntity.getResult();
                    }

                }
                System.out.println(processSample);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}